<?php
class InfomationAction extends BaseAction {
	public function outingList() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Outing = M('Outing'); 
		
		$list = $Outing->select(); 
		$count = count($list);
    	// 导入分页类
   	 	import("ORG.Util.Page");
    	// 实例化分页类
    	$p = new Page($count, 12);
    	$p->setConfig('prev',"<");  
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$p->setConfig('next','>');
    	
    	// 分页显示输出
    	$page = $p->show();
		$list = $Outing->order('outing_id DESC')->limit($p->firstRow.','.$p->listRows)->select(); 
		
		for($i=0;$i<count($list);$i++) {
			if($list[$i]["state"]==0) $list[$i]["state_cn"]="已结束";
			else $list[$i]["state_cn"]="进行中";
		}
		
		$this->assign('page', $page);
		$this->assign('outinglist',$list);
		$this->assign('navi',"乐享活动");
		$this->assign('title',"乐享活动列表");
		$this->display();
	}
	
	public function outingArticle() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Outing = M('Outing');
		$condition['outing_id']=$_GET['id'];
		$info = $Outing->where($condition)->find();
		
		if($_POST['title']) {
			if(is_uploaded_file($_FILES['image']['tmp_name'])){
				$upfile=$_FILES["image"];
				$name=$upfile["name"]; //重命名照片
				$tmp=strtolower(substr($name, -4,4));
				$type=$upfile["type"];
				$size=$upfile["size"];
				$tmp_name=$upfile["tmp_name"];
				$error=$upfile["error"];
				$name=date('YmdHis').$tmp;
				if($error=='0') move_uploaded_file($tmp_name,'Public/Display/outing/'.$name);
				if(is_file('Public/Display/outing/'.$info['cover_image'])) 
					unlink('Public/Display/outing/'.$info['cover_image']);		
 			}
			if($info['title']!=$_POST['title']) $data['title'] = $_POST['title'];
			if($info['host']!=$_POST['host']) $data['host'] = $_POST['host'];
			if($info['out_time']!=$_POST['out_time']) $data['out_time'] = $_POST['out_time'];
			if($info['place']!=$_POST['place']) $data['place'] = $_POST['place'];
			if($info['fee']!=$_POST['fee']) $data['fee'] = $_POST['fee'];
			if($info['number']!=$_POST['number']) $data['number'] = $_POST['number'];
			if($info['reg_time']!=$_POST['reg_time']) $data['reg_time'] = $_POST['reg_time'];
			if($info['reg_tel']!=$_POST['reg_tel']) $data['reg_tel'] = $_POST['reg_tel'];
			if($info['state']!=$_POST['state']) $data['state'] = $_POST['state'];
			if($info['content']!=$_POST['content']) $data['content'] = $_POST['content'];
			if(!empty($name)) $data['cover_image'] = $name;
			
			if($data) {
				$result = $Outing->where($condition)->save($data);
				if($result)
					echo "<script language=\"javascript\">alert('修改成功！');window.location.href='outingArticle/id/".$_GET['id']."';</script>";
				else 
					$this->error ( '数据写入错误！请重试...' );
			} else 
				echo "<script language=\"javascript\">alert('资料没有更新！');window.location.href='outingArticle/id/".$_GET['id']."';</script>";
		} 
		$this->assign('outing',$info);
		$this->assign('navi',"乐享活动内容");
		$this->assign('title',"乐享活动内容列表");
		$this->display();
	}
	
	public function addOuting() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		if($_POST['title']) {
			$Outing = M('Outing');
			
			if(is_uploaded_file($_FILES['image']['tmp_name'])){
				$upfile=$_FILES["image"];
				$name=$upfile["name"]; //重命名照片
				$tmp=strtolower(substr($name, -4,4));
				$type=$upfile["type"];
				$size=$upfile["size"];
				$tmp_name=$upfile["tmp_name"];
				$error=$upfile["error"];
				$name=date('YmdHis').$tmp;
				if($error=='0') move_uploaded_file($tmp_name,'Public/Display/outing/'.$name);		
 			}
 			
 			$data['title']=$_POST['title'];
			$data['host']=$_POST['host'];
			$data['out_time']=$_POST['out_time'];
			$data['place']=$_POST['place'];
			$data['fee']=$_POST['fee'];
			$data['number']=$_POST['number'];
			$data['reg_time']=$_POST['reg_time'];
			$data['reg_tel']=$_POST['reg_tel'];
			$data['hotline']=$_POST['hotline'];
			if(!empty($name)) $data['cover_image']=$name;
			$data['state']=$_POST['state'];
			$data['content']=$_POST['content'];
			
			$result = $Outing->add($data);
			if($result)
				echo "<script language=\"javascript\">alert('添加成功！');window.location.href='outingList';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		} else {
			$this->assign('navi',"活动添加");
			$this->assign('title',"添加乐享活动");
			$this->display();
		}
	}
	
	public function deleteOuting() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Outing = M('Outing');
		$condition['outing_id']=$_GET['id'];
		$info = $Outing->where($condition)->find();
		if(is_file('Public/Display/outing/'.$info['cover_image'])) 
			unlink('Public/Display/outing/'.$info['cover_image']);	
		$Outing->where($condition)->delete();
		$this->redirect('outingList');
	}
	
public function storyList() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Story = M('Story'); 
		
		$list = $Story->select(); 
		$count = count($list);
    	// 导入分页类
   	 	import("ORG.Util.Page");
    	// 实例化分页类
    	$p = new Page($count, 12);
    	$p->setConfig('prev',"<");  
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$p->setConfig('next','>');
    	
    	// 分页显示输出
    	$page = $p->show();
		$list = $Story->order('story_id DESC')->limit($p->firstRow.','.$p->listRows)->select(); 
		
		for($i=0;$i<count($list);$i++) {
			if($list[$i]["state"]==0) $list[$i]["state_cn"]="不可用";
			else $list[$i]["state_cn"]="可用";
		}
		
		$this->assign('page', $page);
		$this->assign('storylist',$list);
		$this->assign('navi',"成功晒客");
		$this->assign('title',"成功晒客列表");
		$this->display();
	}
	
	public function storyArticle() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Story = M('Story');
		$condition = $_GET['id'];
		$info = $Story->where($condition)->find();
		
		if($_POST['title']) {
			if(is_uploaded_file($_FILES['image']['tmp_name'])){
				$upfile=$_FILES["image"];
				$name=$upfile["name"]; //重命名照片
				$tmp=strtolower(substr($name, -4,4));
				$type=$upfile["type"];
				$size=$upfile["size"];
				$tmp_name=$upfile["tmp_name"];
				$error=$upfile["error"];
				$name=date('YmdHis').$tmp;
				if($error=='0') move_uploaded_file($tmp_name,'Public/Display/story/'.$name);
				if(is_file('Public/Display/story/'.$info['pic_url'])) 
					unlink('Public/Display/story/'.$info['pic_url']);		
 			}
			if($info['title']!=$_POST['title']) $data['title'] = $_POST['title'];
			if($info['male']!=$_POST['male']) $data['male'] = $_POST['male'];
			if($info['female']!=$_POST['female']) $data['female'] = $_POST['female'];
			if($info['anniversary']!=$_POST['anniversary']) $data['anniversary'] = $_POST['anniversary'];
			if($info['ann_time']!=$_POST['ann_time']) $data['ann_time'] = $_POST['ann_time'];
			if($info['state']!=$_POST['state']) $data['state'] = $_POST['state'];
			if($info['intro']!=$_POST['intro']) $data['intro'] = $_POST['intro'];
			if($info['content']!=$_POST['content']) $data['content'] = $_POST['content'];
			if(!empty($name)) $data['pic_url'] = $name;
			
			if($data) {
				$result = $Story->where($condition)->save($data);
				if($result)
					echo "<script language=\"javascript\">alert('修改成功！');window.location.href='storyArticle/id/".$_GET['id']."';</script>";
				else 
					$this->error ( '数据写入错误！请重试...' );
			} else 
				echo "<script language=\"javascript\">alert('资料没有更新！');window.location.href='storyArticle/id/".$_GET['id']."';</script>";
		} 
		$this->assign('story',$info);
		$this->assign('navi',"成功晒客内容");
		$this->assign('title',"成功晒客内容列表");
		$this->display();
	}
	
	public function addStory() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		if($_POST['title']) {
			$Story = M('Story');
			
			if(is_uploaded_file($_FILES['image']['tmp_name'])){
				$upfile=$_FILES["image"];
				$name=$upfile["name"]; //重命名照片
				$tmp=strtolower(substr($name, -4,4));
				$type=$upfile["type"];
				$size=$upfile["size"];
				$tmp_name=$upfile["tmp_name"];
				$error=$upfile["error"];
				$name=date('YmdHis').$tmp;
				if($error=='0') move_uploaded_file($tmp_name,'Public/Display/story/'.$name);		
 			}
 			
 			$data['title']=$_POST['title'];
			$data['male']=$_POST['male'];
			$data['female']=$_POST['female'];
			$data['anniversary']=$_POST['anniversary'];
			$data['ann_time']=$_POST['ann_time'];
			if(!empty($name)) $data['pic_url']=$name;
			$data['state']=$_POST['state'];
			$data['intro']=$_POST['intro'];
			$data['content']=$_POST['content'];
			
			$result = $Story->add($data);
			if($result)
				echo "<script language=\"javascript\">alert('添加成功！');window.location.href='storyList';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		} else {
			$this->assign('navi',"故事添加");
			$this->assign('title',"添加成功晒客");
			$this->display();
		}
	}
	
	public function deleteStory() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Story = M('Story');
		$condition['story_id']=$_GET['id'];
		$info = $Story->where($condition)->find();
		if(is_file('Public/Display/story/'.$info['pic_url'])) 
			unlink('Public/Display/story/'.$info['pic_url']);	
		$Story->where($condition)->delete();
		$this->redirect('storyList');
	}
	
public function newsList() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$News= M('News'); 
		
		$list = $News->select(); 
		$count = count($list);
    	// 导入分页类
   	 	import("ORG.Util.Page");
    	// 实例化分页类
    	$p = new Page($count, 12);
    	$p->setConfig('prev',"<");  
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$p->setConfig('next','>');
    	
    	// 分页显示输出
    	$page = $p->show();
		$list = $News->order('news_id DESC')->limit($p->firstRow.','.$p->listRows)->select(); 
		
		for($i=0;$i<count($list);$i++) {
			if($list[$i]["state"]==0) $list[$i]["state_cn"]="不可用";
			else $list[$i]["state_cn"]="可用";
		}
		
		$this->assign('page', $page);
		$this->assign('newslist',$list);
		$this->assign('navi',"潮流婚恋");
		$this->assign('title',"潮流婚恋列表");
		$this->display();
	}
	
	public function newsArticle() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$News = M('News');
		$condition['news_id']=$_GET['id'];
		$info = $News->where($condition)->find();
		
		if($_POST['title']) {
			if(is_uploaded_file($_FILES['image']['tmp_name'])){
				$upfile=$_FILES["image"];
				$name=$upfile["name"]; //重命名照片
				$tmp=strtolower(substr($name, -4,4));
				$type=$upfile["type"];
				$size=$upfile["size"];
				$tmp_name=$upfile["tmp_name"];
				$error=$upfile["error"];
				$name=date('YmdHis').$tmp;
				if($error=='0') move_uploaded_file($tmp_name,'Public/Display/news/'.$name);
				if(is_file('Public/Display/news/'.$info['pic_url'])) 
					unlink('Public/Display/news/'.$info['pic_url']);		
 			}
			if($info['title']!=$_POST['title']) $data['title'] = $_POST['title'];
			if($info['type']!=$_POST['type']) $data['type'] = $_POST['type'];
			if($info['ann_time']!=$_POST['ann_time']) $data['ann_time'] = $_POST['ann_time'];
			if($info['state']!=$_POST['state']) $data['state'] = $_POST['state'];
			if($info['content']!=$_POST['content']) $data['content'] = $_POST['content'];
			if(!empty($name)) $data['pic_url'] = $name;
			
			if($data) {
				$result = $News->where($condition)->save($data);
				if($result)
					echo "<script language=\"javascript\">alert('修改成功！');window.location.href='newsArticle/id/".$_GET['id']."';</script>";
				else 
					$this->error ( '数据写入错误！请重试...' );
			} else 
				echo "<script language=\"javascript\">alert('资料没有更新！');window.location.href='newsArticle/id/".$_GET['id']."';</script>";
		} 
		$this->assign('news',$info);
		$this->assign('navi',"潮流婚恋");
		$this->assign('title',"潮流婚恋内容列表");
		$this->display();
	}
	
	public function addNews() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		if($_POST['title']) {
			$News = M('News');
			
			if(is_uploaded_file($_FILES['image']['tmp_name'])){
				$upfile=$_FILES["image"];
				$name=$upfile["name"]; //重命名照片
				$tmp=strtolower(substr($name, -4,4));
				$type=$upfile["type"];
				$size=$upfile["size"];
				$tmp_name=$upfile["tmp_name"];
				$error=$upfile["error"];
				$name=date('YmdHis').$tmp;
				if($error=='0') move_uploaded_file($tmp_name,'Public/Display/news/'.$name);		
 			}
 			
 			$data['title']=$_POST['title'];
			$data['type']=$_POST['type'];
			$data['ann_time']=$_POST['ann_time'];
			if(!empty($name)) $data['pic_url']=$name;
			$data['state']=$_POST['state'];
			$data['content']=$_POST['content'];
			
			$result = $News->add($data);
			if($result)
				echo "<script language=\"javascript\">alert('添加成功！');window.location.href='newsList';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		} else {
			$this->assign('navi',"新闻添加");
			$this->assign('title',"添加潮流婚恋");
			$this->display();
		}
	}
	
	public function deleteNews() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$News = M('News');
		$condition['news_id']=$_GET['id'];
		$info = $News->where($condition)->find();
		if(is_file('Public/Display/news/'.$info['pic_url'])) 
			unlink('Public/Display/news/'.$info['pic_url']);	
		$News->where($condition)->delete();
		$this->redirect('newsList');
	}
}